package com.crl.ssc.dic.dao;

import com.cars.util.string.StringUtil;
import com.crl.dao.BaseDao;
import com.crl.ssc.dic.model.DicTest;
import com.crl.ssc.dic.vo.DicTestSearchVO;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @description: 字典管理-测试数据表Dao
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020-08-04 00:41:31
 */
@Repository
public class DicTestDao extends BaseDao<DicTest, DicTestSearchVO> {
    /**
     * 新增
     *
     * @param dicTest
     * @return
     */
    public int add(DicTest dicTest) {
        String sql = "INSERT INTO td_dic_test(name,age,length,birth,edu) " +
                "VALUES(:name,:age,:length,:birth,:edu)";
        return insert(sql, dicTest);
    }

    /**
     * 修改
     *
     * @param dicTest
     * @return
     */
    public int update(DicTest dicTest) {
        String sql = "UPDATE td_dic_test SET name=:name,age=:age,length=:length,birth=:birth,edu=:edu " +
                    "WHERE id=:id";
        return update(sql, dicTest);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public int delete(Long id) {
        String sql = "DELETE FROM td_dic_test WHERE id=?";
        return delete(sql, id);
    }
    /**
     * 列表
     *
     * @param dicTestSearchVO
     * @return
     */
    public List<DicTest> list(DicTestSearchVO dicTestSearchVO) {
        String sql = "SELECT id,name,age,length,birth,edu FROM td_dic_test WHERE 1=1 ";
        sql += createSearchSQL(dicTestSearchVO);
        sql += " ORDER BY id ASC";
        return list(sql, dicTestSearchVO);
    }
    /**
       * 拼接查询条件
       *
       * @param dicTestSearchVO
       * @return
    */
    private String createSearchSQL(DicTestSearchVO dicTestSearchVO) {
        String sql = "";
        if (StringUtil.isNotNullOrEmpty(dicTestSearchVO.getName())) {
			sql += " AND name =:name ";
		}
        return sql;
    }

    /**
     * 获取单个
     *
     * @param id
     * @return
     */
    public DicTest get(Long id) {
        String sql = "SELECT id,name,age,length,birth,edu FROM td_dic_test WHERE id=?";
        return get(sql, id);
    }
}
